package Operations;
import Data.DbData;
import Operations.Calculate.ACalculate;
import Data.RuleDB;
import Enumeration.TypesResult;
import GUI.ResultData;
import Operations.Calculate.Average;
import Operations.Calculate.Max;
import Operations.Calculate.Min;
import java.util.ArrayList;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author Martin
 * @version 1.0
 * @created 24-III-2012 8:05:05
 */
public class SimpleFactory {

	private ACalculate aCalculate;
        private Thread thread;
	//public RuleDB m_RuleDB;
	//public ACalculate m_ACalculate;

	public SimpleFactory(){
           // aCalculate = new Min(dbData, null, resultData);
            
	}

	/**
	 * Staci to takhle, ten zbytek tady byl z predchoziho navrhu, kdy to melo vypadat trosku jinak
	 * @param dbData
	 * @param resultData
	 * @param name
	 */
	public void createOperation(ArrayList<DbData> dbData, ResultData resultData, TypesResult name){
            switch(name)
            {
                case all:                    
                    aCalculate = new Min(dbData,  new Max(dbData, new Average(dbData, null, resultData), resultData), resultData);
                    break;
                    
                case average:
                    aCalculate = new Average(dbData, null, resultData);
                    break;
                    
                case max:
                    aCalculate = new Max(dbData, null, resultData);
                    break;
                    
                case min:
                    aCalculate = new Min(dbData, null, resultData);
                    break;                   
            }
            /*
            do{     
                aCalculate.doOperation();
                aCalculate = aCalculate.getNext();
            }while(aCalculate!=null);*/
            thread = new Thread(aCalculate);
            thread.start();
            //musime cekat na ukonceni!!!
            while(true) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException ex) {
                    Logger.getLogger(SimpleFactory.class.getName()).log(Level.SEVERE, null, ex);
                }
                //thread.join();
                if(!thread.isAlive()) break;               
            }
            //aCalculate.doOperation();
            
	}

}